#/usr/bin/Rscript
library("ggplot2")

on_100 <- read.table("on/profits.dat")$V1
op_100 <- read.table("rf/profits.dat")$V1
ut_100 <- read.table("ut/profits.dat")$V1
iosup_100 <- read.table("iosup/profits.dat")$V1
super_100 <- read.table("super/profits.dat")$V1

#Ganhos para risco de 1_5_10%

gop_100 <- (op_100 - on_100) / abs(on_100)
gut_100 <- (ut_100 - on_100) / abs(on_100)
giosup_100 <- (iosup_100 - on_100) / abs(on_100)
gsuper_100 <- (super_100 - on_100) / abs(on_100)

#100 usuários
jpeg("ganhos_100.jpg")


heuristica <- c("RF", "UT", "COHR", "SUPER")
risco <- c(1, 1, 1, 1)
ganho <- c(mean(gop_100), mean(gut_100), mean(giosup_100), mean(gsuper_100))
interval <- c( 1.96*sd(gop_100)/sqrt(length(gop_100)), 1.96*sd(gut_100)/sqrt(length(gut_100)), 1.96*sd(giosup_100)/sqrt(length(giosup_100)), 1.96*sd(gsuper_100)/sqrt(length(gsuper_100)) )

pd <- position_dodge(.1) # move them .05 to the left and right
dados <- data.frame(heur=heuristica, ris=risco, gan=ganho, ci=interval)

limits <- aes(x=ris, y=100 * gan, ymin=100 * (gan-ci), ymax=100 * (gan+ci), colour=heur, fill=heur, shape=heur)
ggplot(dados, limits) + 
    geom_point(position=pd, size=3) + xlab("Risco de negação de serviço") + ylab("Ganho") + opts(title="Ganho de heurísticas em relação a heurística ON") + theme_bw() + scale_y_continuous(breaks=c(5, 7, 9, 10, 11, 12)) + scale_x_continuous(breaks=c(0, 5, 6, 7, 10)) + scale_shape_manual(values=c(19, 3, 0, 8)) + geom_errorbar(limits)
 
dev.off()

